var getSimilarQuestion = function(){

    //获得相似问题
    $.ajax({
        url:WebSite.SearchResultPage.similarQuestion,
        type:"POST",
        data:{
            "pk_question" : getUrlParam("pk_question"),
            "count"       : 7
        },
        dataType          : "json",


        success:function(result){
            var questionData = result.resultData;
            for (var i = 0, len = questionData.length; i < len; i++) {
                var record = questionData[i];
                record.es_link = similarQuestionlPath(record);
            }

            var questionTemplate = Handlebars.compile($("#question_div_template").html());
            $("#question_info").html(questionTemplate(questionData));
        },
        error:function(){
            alert("请求数据错误");
        }
    });


};

//相似问题的路径
var similarQuestionlPath = function(record){
    var isEssence = record.essence;     //0不是精华   1代表精华
    var status = record.status;         //1待解答  2待处理   3已解决
    if(isEssence == 1){
        return WebSite.AskerSolvedPage.url + "&pk_question=" + record.pk_sool_question;
    }else if(isEssence == 0 && status == 1){
        return WebSite.ReplyerUnansweredPage.url + "&pk_question=" + record.pk_sool_question;
    }else if(isEssence == 0 && status == 2){

    }else if(isEssence == 0 && status == 3){
        return WebSite.AskerSolvedPage.url + "&pk_question=" + record.pk_sool_question;
    }else{
        return WebSite.AskerSolvedPage.url + "&pk_question=" + record.pk_sool_question;
    }
}

//相似问题的加载
var loadSimilaryQuestion = function(){
    var similaryQuestion = '<script type="text/x-handlebars-template" id="question_div_template">'
        +'<h4 class="dq-frame-right-title doc-similary-title">'
        +'<img src="static/images/similaryQuestion.png" alt="" height="25px" width="25px">&nbsp;'
        +'相似问题'
        +'</h4>'
        +'<ul class="dq-frame-right-context am-text-truncate doc-similary-context" id="doc-similary-ul">'
        +'{{#each this}}'

        +'{{#isEssenceQuestion essence}}'
        +'<li><a href="{{es_link}}">{{similaryQuestion_length question_title}}</a></li>'
        +'{{else}}'
        +'<li><a href="{{es_link}}">{{similaryQuestion_length question_title}}</a>&nbsp;<i class="fa fa-diamond dq-diamond-color"></i></li>'
        +'{{/isEssenceQuestion}}'

        +'{{/each}}'
        +'</ul>'
        +'</script>';

    document.write(similaryQuestion)
}

